"""
Tiny QA 主应用
"""
from flask import Flask, render_template
from flask_cors import CORS
import os
from app.core.config import config
from app.api.routes import api
from app.web.routes import web


def create_app():
    """创建Flask应用"""
    app = Flask(__name__)
    
    # 配置CORS
    CORS(app)
    
    # 注册蓝图
    app.register_blueprint(api, url_prefix='/api')
    app.register_blueprint(web)
    
    # 配置模板目录
    app.template_folder = 'templates'
    app.static_folder = 'static'
    
    return app


def main():
    """主函数"""
    app = create_app()
    
    # 获取配置
    host = config.get('app.host', '0.0.0.0')
    port = config.get('app.port', 5001)
    debug = config.get('app.debug', True)
    
    print(f"启动 Tiny QA 服务...")
    print(f"访问地址: http://{host}:{port}")
    print(f"API地址: http://{host}:{port}/api")
    
    app.run(host=host, port=port, debug=debug)


if __name__ == '__main__':
    main() 